package com.hd.day03;

import java.util.Arrays;

public class TwoNumSum {


    class Solution {
        public int[] twoSum(int[] nums, int target) {

            int[] retVal = new int[2];

            for (int i = 0; i < nums.length - 1; i++) {
                for (int j = i + 1; j < nums.length; j++) {
                    if (nums[i] + nums[j] == target) {
                        retVal[0] = i;
                        retVal[1] = j;
                        return retVal;
                    }
                }
            }
            return retVal;
        }
    }


    public static void main(String[] args) {
        int[] nums = new int[]{2, 12, 7, 11, 15};
        int target = 9;
        int[] retVal = new int[2];
        Arrays.sort(nums);
        if (nums[0] > target) {
            return;
        }
        System.out.println(Arrays.toString(nums));

        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    retVal[0] = i;
                    retVal[1] = j;
                    System.out.println(Arrays.toString(retVal));
                }
            }
        }
    }


}
